package cn.net.withub.dataCollector.web.collector;

import cn.net.withub.dataCollector.common.model.TCollectorConfig;
import org.apache.log4j.Logger;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yuanjie on 2018/5/8.
 */
public class CollectorReflect {

    private Logger log = Logger.getLogger(this.getClass());

    //反射调用方法
    public static void reflectUtil(TCollectorConfig config) throws Exception{
        Object obj = null;
        Class<?> clazz = null;
        Map<String,Object> paramMap = new HashMap<String, Object>();

        //通过类名获取类的Class对象
        clazz = Class.forName(config.getClassPath());

        //通过反射获取Class
        obj = clazz.newInstance();

        //通过反射获取方法
        //Method m = clazz.getMethod(config.getMethodName(), new Class[]{Map.class});
        Method m = clazz.getMethod(config.getMethodName(), new Class[]{TCollectorConfig.class});
        //调用方法
        //m.invoke(obj, new Object[]{paramMap});
        m.invoke(obj, new Object[]{config});
    }
}
